<template>
  <div class="component-root-container">
    <el-header>
      <el-form ref="dataBindRule" :rules="dataBindRule" :model="dataBind" label-width="120px" label-position="right">
        <el-row>
          <el-col :span="8">
            <el-form-item label="资源ID:" prop="resId">
              <el-input v-model="dataBind['resId']" placeholder="请输入" @input="change($event)" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8" class="col_button">
            <div class="button">
              <el-button class="query" @click="buttonClick">
                  查询
                </el-button>
                <el-button class="query" @click="reset">
                  重置
              </el-button>
            </div>
            
          </el-col>
        </el-row>
      </el-form>
    </el-header>
    <el-main>
      <div class="contentInfo" style="margin-bottom:20px;">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景使用情况
          </el-col>
        </el-row>
        <el-row>
          <div class="inline">
            <div><span>调用次数/日：</span><span>{{ query.count }}</span></div>
            <div><span>拦截比率：</span><span>{{ query.rate }}</span></div>
            <div><a class="link" href="javascript:;" @click="$router.push({name:'biz-ml'})">详情</a></div>
          </div>
        </el-row>
      </div>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            场景说明
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">资源资产管理系统出现站址间转移、省市间资产调拨、省公司内资产调拨、资产闲置、资产利旧、资源删除、资产报废等发起场景时，通过系统内存数据库进行沉淀固化打标数据及绑定订单判断，如果已固化的资源在营收系统有绑定的订单，则不允许发起流程。</div>
          </div>
          <div class="page-tip">
            <div class="params-tip"><span>示例参数</span>：资源ID:003588430200000051323537</div>
          </div>
        </el-row>
      </div>
    </el-main>
    <el-main>
      <div class="contentInfo">
        <el-row>
          <el-col class="header-title">
            <span class="header-vertical" />
            校验结果
          </el-col>
        </el-row>
        <el-row>
          <div class="page-tip">
            <div class="description">
              <el-row v-for="(item,index) in dialogData" :key="index" class="dialog-row">
                <el-col :span="24">
                  资源ID: {{ item.resId }}
                </el-col>
                <el-col>
                  结果: {{ item.message || '无' }}
                </el-col>
              </el-row>
            </div>
          </div>
        </el-row>
      </div>
    </el-main>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        dialogVisible: false,
        query:{
           count:0,
           rate:'--'
        },
        dataBind: {
          resId: ''
        },
        escape: {
          '0': '未固化',
          '1': '已固化'
        },
        dialogData: [],
        dataBindRule: {
          resId: [{
            required: true,
            message: '请输入资源ID',
            trigger: 'blur'
          }]
        }
      }
    },
    created() {
      this.queryPageCount('2.3')
    },
    mounted() {},
    methods: {
      async buttonClick() {
        try {
          this.dialogData = []
          await this.$refs['dataBindRule'].validate()
          const data = {
            datas: [{
              resId: this.dataBind['resId']
            }]
          }
          const r = await this.$http({
            url: this.$http.adornBizUrl('/order/curingBinding'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify(data), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          console.log(r)
          if (r.data.data.length > 0) {
            this.dialogData = r.data.data
          }
        } catch (e) {
          console.log(e)
        } finally {
          this.listLoading = false
        }
      },
      reset() {
        this.dataBind = {
          resId: ''
        }
        this.dialogData = []
        this.$refs['dataBindRule'].clearValidate()
      },
      change(e) {
        this.$forceUpdate()
      },
      async queryPageCount(scene) {
        try {
          const r = await this.$http({
            url: this.$http.adornBizUrl('/log/queryStatistics'),
            method: 'post',
            data: this.$http.adornData('param=' + JSON.stringify({scene:scene}), false),
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
            }
          })
          if(r.data.data && r.data.data.length >0){
              var result = r.data.data[0];
              this.query.count=result.cnt||'0';
              this.query.rate=(result.per==null?'--': (result.per*100).toFixed(1)+'%');
          }
        } catch (e) {
          console.log(e)
        } finally {
        }
      }
    }
  }
</script>

<style scoped lang="scss">
  @import "../../../assets/scss/_formatQueryPage";
  @include formatQueryPage(0, 60%, left);
  .el-input {
    width: 60%;
  }

  .query {
    color: rgba(255, 255, 255, 1);
    background: rgba(235, 75, 75, 1);
    border-radius: 6px;
    border-color: rgba(235, 75, 75, 1);
  }
</style>
